<?php
namespace app\admin\controller;
use app\admin\common\Base;
use app\admin\model\BaseCallCenter;
use think\Exception;
use think\facade\Request;
use app\admin\service\CallCenter as CC;
use app\admin\service\TencentService;

class Api extends Base
{

    //输入关键词搜索小区地址
    public function searchAddr(TencentService $ts){
        $region = $this->request->get('region', '', 'trim');
        $keyword = $this->request->get('keyword', '', 'trim');

        $json = [
            "message"   =>  "",
            "value"   =>  [],
            "code"   =>  200,
        ];
        if(strlen($keyword) > 1){
            $data = $ts->searchAddr($keyword, $region);

            foreach($data as &$row){
                //去掉地址前面的：省-市-区
                if($row->province == $row->city){   //【特殊】直辖市
                    $row->address = str_replace($row->city.$row->district, '', $row->address);
                }else{
                    $row->address = str_replace($row->province.$row->city.$row->district, '', $row->address);
                }
            }
            unset($row);
            $json['value'] = $data;

        }

        return json($json);
    }

}